Skip to content

refactor: DRY Page class, fix bugs, enforce autoload convention - #16

Merged
ronaldtse merged 4 commits into
mainfrom
refactor/architecture-improvements
May 13, 2026
Merged

refactor: DRY Page class, fix bugs, enforce autoload convention#16
ronaldtse merged 4 commits into
mainfrom
refactor/architecture-improvements

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Architecture and code quality improvements identified during comprehensive TODO parity audit.

1. Page class DRY refactor

  • Cache Nokogiri document: parse once, reuse across 9 extraction methods (title, links, meta_tags, headings, images, forms, scripts, microposts, detect_html_charset). Eliminates 8 redundant HTML parses per page.
  • Deduplicate to_h/as_json via transform_values
  • Fix resolve_page_url prefix matching: "http" matched httpserver.com incorrectly. Now explicitly checks "http:" and "https:".

2. Bug fixes

  • BulkDownloader: tmp_path cleanup was in fetch_and_save rescue but tmp_path is a local variable in write_page_filedefined?(tmp_path) was always false. Moved cleanup into the correct scope.
  • DownloadState: cleanup_stale duplicated file-existence logic from stale_entries. Now reuses it (DRY).

3. Class-per-file autoload convention

  • Extract CoverageAnalyzer from coverage_report.rb into coverage_analyzer.rb
  • Extract HealthReport/HealthDetail Structs from archive_health_check.rb into health_report.rb
  • Remove redundant inline require "nokogiri" from SnapshotDiff

Test Results

561 examples, 0 failures

ronaldtse added 4 commits May 13, 2026 21:13
Parse Nokogiri document once and reuse across all extraction methods
(title, links, meta_tags, headings, images, forms, scripts, microposts).
This eliminates 9 redundant HTML parses per page.

Also:
- Deduplicate to_h/as_json via transform_values
- Fix resolve_page_url to match http:/https: explicitly instead of
  bare 'http' prefix (could match 'httpserver.com' incorrectly)
BulkDownloader: Move tmp_path cleanup from fetch_and_save (where it was
out of scope and never executed) into write_page_file where the variable
is actually defined.

DownloadState: DRY cleanup_stale to reuse stale_entries instead of
duplicating the file-existence logic.
Extract CoverageAnalyzer from coverage_report.rb into its own file.
Extract HealthReport and HealthDetail Structs from
archive_health_check.rb into health_report.rb.
Remove redundant inline 'require nokogiri' from SnapshotDiff.

Ensures each autoloaded constant maps to its own file, following
the Archaeo convention established in lib/archaeo.rb.
@ronaldtse
ronaldtse merged commit 2a929cd into main May 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant